package com.beiing.tianshuai.tianshuai.dongtai;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;
import com.beiing.tianshuai.tianshuai.adapter.DynamicPraiseBaseAdapter;
import com.beiing.tianshuai.tianshuai.adapter.DynamicRelayPraiseBaseAdapter;
import com.beiing.tianshuai.tianshuai.base.BaseActivity;
import com.beiing.tianshuai.tianshuai.entity.DynamicDetailBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicRelayDetailBean;
import com.beiing.tianshuai.tianshuai.mine.ui.NewPersonalIndexActivity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by magikliu on 2017/9/22.
 */

public class PraiseDetailActivity extends BaseActivity {

    private DynamicDetailBean.DataBean dataBean;
    private List<DynamicDetailBean.DataBean.UserThingBean> userThingBeanList;

    private DynamicRelayDetailBean.DataBean relayDataBean;
    private List<DynamicRelayDetailBean.DataBean.UserThingBean> relayUserThingBeanList;
    private DynamicPraiseBaseAdapter mAdapter;
    private DynamicRelayPraiseBaseAdapter relayAdapter;

    @BindView(R.id.toolbar_center_title)
    TextView toolbarCenterTitle;
    @BindView(R.id.toolbar_tv_title)
    TextView toolbarTvTitle;
    @BindView(R.id.toolbar_iv_back)
    ImageView toolbarIvBack;
    @BindView(R.id.praise_list)
    ListView praiseList;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_dynamic_praise_detail;
    }

    @Override
    protected void init() {

        toolbarCenterTitle.setVisibility(View.VISIBLE);
        toolbarTvTitle.setVisibility(View.GONE);
        toolbarIvBack.setVisibility(View.VISIBLE);

        /**  点赞列表数据部分 **/
        if(getIntent().getStringExtra("from_activity").equals("dynamic")){
            dataBean = (DynamicDetailBean.DataBean) getIntent().getExtras().get("dynamicDetail");
            userThingBeanList = dataBean.getUserThing();
            mAdapter = new DynamicPraiseBaseAdapter(mContext, userThingBeanList);
            praiseList.setAdapter(mAdapter);
            toolbarCenterTitle.setText("赞（"+ userThingBeanList.size() + "）");

            praiseList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Intent intent = new Intent(mContext, NewPersonalIndexActivity.class);
                    intent.putExtra("uid", userThingBeanList.get(i).getId());
                    startActivity(intent);
                }
            });
        } else if (getIntent().getStringExtra("from_activity").equals("dynamic_relay")){
            relayDataBean = (DynamicRelayDetailBean.DataBean) getIntent().getExtras().get("dynamicDetail");
            relayUserThingBeanList = relayDataBean.getUserThing();
            relayAdapter = new DynamicRelayPraiseBaseAdapter(mContext, relayUserThingBeanList);
            praiseList.setAdapter(relayAdapter);
            toolbarCenterTitle.setText("赞（"+ relayUserThingBeanList.size() + "）");

            praiseList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Intent intent = new Intent(mContext, NewPersonalIndexActivity.class);
                    intent.putExtra("uid", relayUserThingBeanList.get(i).getId());
                    startActivity(intent);
                }
            });
        }

        /**  标题部分  **/
        toolbarIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


    }

}
